package com.xinggq.auth.api.itf;

import com.xinggq.auth.api.dto.login.LoginRequest;
import com.xinggq.auth.api.dto.login.LoginResponse;
import com.xinggq.auth.api.dto.token.RefreshTokenRequest;
import com.xinggq.common.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 登陆管理API接口
 *
 * @author xinggq
 * @since 2024-10-20
 */
@Tag(name = "登陆管理", description = "登陆管理相关接口")
@RequestMapping("/auth/login")
public interface LoginManagerApi {


  /**
   * 登入接口
   * @param loginRequest
   * @return
   */
  @PostMapping("/log-in")
  @Operation(summary = "用户登录")
  CommonResult<LoginResponse> login(@Valid @RequestBody LoginRequest loginRequest);

  /**
   * 登出接口
   * @param authorization
   * @param refreshToken
   * @return
   */
  @PostMapping("/log-out")
  CommonResult<Void> logout(
      @RequestHeader(value = "Authorization", required = false) String authorization,
      @RequestHeader(value = "Refresh-Token", required = false) String refreshToken
  );

  /**
   * 刷新令牌接口
   * @param refreshTokenRequest 刷新令牌请求
   * @return 新的登录响应信息
   */
  @PostMapping("/refresh")
  @Operation(summary = "刷新访问令牌", description = "使用刷新令牌获取新的访问令牌")
  CommonResult<LoginResponse> refreshToken(@Valid @RequestBody RefreshTokenRequest refreshTokenRequest);


}
